#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int N=1e8+10;

int a[N],b[N];
int n;
pair<int,int> node[N];
vector<int> ret;
int dfs(int root,int left,int right)
{
	if(left>right || root<1 || root>n)
		return -1;
	int pos=left;
	while(pos<=right && a[root]!=b[pos])
		pos++;
	node[a[root]].first=dfs(root-1-right+pos,left,pos-1);
	node[a[root]].second=dfs(root-1,pos+1,right);
	return a[root];	
}
int main()
{
	
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
		
	queue<int> q;
	q.push(dfs(n,1,n));
	while(q.size())
	{
		int u=q.front();
		ret.push_back(u);
		q.pop();
		if(node[u].first!=-1)
			q.push(node[u].first);
		if(node[u].second!=-1)
			q.push(node[u].second);
		
	}
	for(int i=0;i<ret.size();i++)
	{
		if(i)
		{
			cout<<' '<<ret[i];
		}
		else{
			cout<<ret[i];
		}
	}
	return 0;
}
